﻿using AiXiu.DAL;
using AiXiu.IBLL;

namespace AiXiu.BLL
{
    /// <summary>
    /// 点赞业务逻辑类
    /// </summary>
    public class LikeManager : ILikeManager
    {
        private const string keyPrefix = "VideoLike";

        /// <summary>
        /// 点赞计数
        /// </summary>
        /// <param name="videoId">视频Id</param>
        /// <returns></returns>
        public long Count(string videoId)
        {
            string key = $"{keyPrefix}_{videoId}";
            return RedisHelper.SetLength(key);
        }

        /// <summary>
        /// 是否已点赞
        /// </summary>
        /// <param name="videoId">视频Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public bool IsLike(string videoId, int userId)
        {
            string key = $"{keyPrefix}_{videoId}";
            return RedisHelper.SetContains(key, userId);
        }

        /// <summary>
        /// 添加点赞
        /// </summary>
        /// <param name="videoId">视频Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public bool AddLike(string videoId, int userId)
        {
            string key = $"{keyPrefix}_{videoId}";
            return RedisHelper.SetAdd(key, userId);
        }

        /// <summary>
        /// 移除点赞
        /// </summary>
        /// <param name="videoId">视频Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public bool RemoveLike(string videoId, int userId)
        {
            string key = $"{keyPrefix}_{videoId}";
            return RedisHelper.SetRemove(key, userId);
        }
    }
}